# -*- coding:utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from httpbasic import getmgr, postmgr
from Models import *
import json 
from urlparse import urlparse

__username = None
__type = None
__cookie = None
def accept(sheet):
	if not type(sheet) == Sheet:
		return 

	
	params = {'_rel':'sheet-listUndo','urlName':sheet.urlName, 'sheetId':sheet.sheetId2, 'sheetType':sheet.sheetType, 'processDefName':sheet.processDefName, 'baseSheetId':sheet.baseSheetId, 'activeDefId':sheet.activeDefId, 'activeInsId':sheet.activeInsId, 'workItemId':sheet.workItemId, 'workItemState':sheet.workItemState,'processInsId':sheet.processInsId}
	
	with getmgr('10.97.87.200',sheet.nexturl,9084) as response1:
		url = urlparse(response1.msg['Location'])
		with getmgr(url.hostname, url.path + '?' + url.query, 9086) as response2:
			global __cookie
			__cookie = response2.msg['Set-Cookie']
			headers = {'Content-type':'application/x-www-form-urlencoded', 'Accept':'text/plain','Cookie':__cookie}
			with postmgr('10.97.87.200','/eoms/wffrom/inst/accept',9088,params,headers) as response3:
				s = response3.read()
				s = s.encode('gbk')  
				return s
		

		
